test the move and swap functions on a store with only one node.
authorKristian Rietveld <kris@imendio.com>
Thu, 13 Dec 2007 16:28:12 +0000 (16:28 +0000)
committerKristian Rietveld <kristian@src.gnome.org>
Thu, 13 Dec 2007 16:28:12 +0000 (16:28 +0000)
2007-12-13  Kristian Rietveld  <kris@imendio.com>

* gtk/tests/liststore.c:
* gtk/tests/treestore.c: test the move and swap functions on a
store with only one node.

svn path=/trunk/; revision=19172

ChangeLog
gtk/tests/liststore.c
gtk/tests/treestore.c

index fbf0036679fc458ff764388da829d772462b54f6..5fa4e99e416ba1279c0653e83875e32774cedafc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-12-13  Kristian Rietveld  <kris@imendio.com>
+
+       * gtk/tests/liststore.c:
+       * gtk/tests/treestore.c: test the move and swap functions on a
+       store with only one node.
+
 2007-12-13  Kristian Rietveld  <kris@imendio.com>
 
        * gtk/gtktestutils.c (gtk_test_init): add a call to
index 3b0334ef15bd6dba955e5d25f84e2e5d91ced13b..b1b10933a0866c2ce08666635315e6fc0d2328a7 100644 (file)
@@ -19,8 +19,6 @@
  */
 
 /* To do:
- *  - We probably want to do all move and swap tests on a 1-item list store
- *    also.
  *  - Test implementations of the interfaces: DnD, sortable, buildable
  *    and the tree model interface itself?
  *  - Need to check if the emitted signals are right.
@@ -273,6 +271,30 @@ list_store_test_swap_end (ListStore     *fixture,
   check_model (fixture, new_order, -1);
 }
 
+static void
+list_store_test_swap_single (void)
+{
+  GtkTreeIter iter;
+  GtkTreeIter iter_copy;
+  GtkListStore *store;
+
+  store = gtk_list_store_new (1, G_TYPE_INT);
+
+  /* Check if swap on a store with a single node does not corrupt
+   * the store.
+   */
+
+  gtk_list_store_append (store, &iter);
+  iter_copy = iter;
+
+  gtk_list_store_swap (store, &iter, &iter);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  g_object_unref (store);
+}
+
 /* move after */
 
 static void
@@ -394,6 +416,35 @@ list_store_test_move_after_NULL (ListStore     *fixture,
   check_model (fixture, new_order, -1);
 }
 
+static void
+list_store_test_move_after_single (void)
+{
+  GtkTreeIter iter;
+  GtkTreeIter iter_copy;
+  GtkListStore *store;
+
+  store = gtk_list_store_new (1, G_TYPE_INT);
+
+  /* Check if move-after on a store with a single node does not corrupt
+   * the store.
+   */
+
+  gtk_list_store_append (store, &iter);
+  iter_copy = iter;
+
+  gtk_list_store_move_after (store, &iter, NULL);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  gtk_list_store_move_after (store, &iter, &iter);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  g_object_unref (store);
+}
+
 /* move before */
 
 static void
@@ -496,6 +547,35 @@ list_store_test_move_before_NULL (ListStore     *fixture,
   check_model (fixture, new_order, -1);
 }
 
+static void
+list_store_test_move_before_single (void)
+{
+  GtkTreeIter iter;
+  GtkTreeIter iter_copy;
+  GtkListStore *store;
+
+  store = gtk_list_store_new (1, G_TYPE_INT);
+
+  /* Check if move-before on a store with a single node does not corrupt
+   * the store.
+   */
+
+  gtk_list_store_append (store, &iter);
+  iter_copy = iter;
+
+  gtk_list_store_move_before (store, &iter, NULL);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  gtk_list_store_move_before (store, &iter, &iter);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  g_object_unref (store);
+}
+
 /* main */
 
 int
@@ -541,6 +621,8 @@ main (int    argc,
   g_test_add ("/list-store/swap-end", ListStore, NULL,
              list_store_setup, list_store_test_swap_end,
              list_store_teardown);
+  g_test_add_func ("/list-store/swap-single",
+                  list_store_test_swap_single);
 
   /* moving */
   g_test_add ("/list-store/move-after-from-start", ListStore, NULL,
@@ -564,6 +646,8 @@ main (int    argc,
   g_test_add ("/list-store/move-after-NULL", ListStore, NULL,
              list_store_setup, list_store_test_move_after_NULL,
              list_store_teardown);
+  g_test_add_func ("/list-store/move-after-single",
+                  list_store_test_move_after_single);
 
   g_test_add ("/list-store/move-before-next", ListStore, NULL,
              list_store_setup, list_store_test_move_before_next,
@@ -583,6 +667,8 @@ main (int    argc,
   g_test_add ("/list-store/move-before-NULL", ListStore, NULL,
              list_store_setup, list_store_test_move_before_NULL,
              list_store_teardown);
+  g_test_add_func ("/list-store/move-before-single",
+                  list_store_test_move_before_single);
 
   return g_test_run ();
 }
index 24d06603327f7194a71c10a19818cdd75198a886..cb7d3563836b49d76fd2a8d471df188f43323037 100644 (file)
@@ -271,6 +271,30 @@ tree_store_test_swap_end (TreeStore     *fixture,
   check_model (fixture, new_order, -1);
 }
 
+static void
+tree_store_test_swap_single (void)
+{
+  GtkTreeIter iter;
+  GtkTreeIter iter_copy;
+  GtkTreeStore *store;
+
+  store = gtk_tree_store_new (1, G_TYPE_INT);
+
+  /* Check if swap on a store with a single node does not corrupt
+   * the store.
+   */
+
+  gtk_tree_store_append (store, &iter, NULL);
+  iter_copy = iter;
+
+  gtk_tree_store_swap (store, &iter, &iter);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  g_object_unref (store);
+}
+
 /* move after */
 
 static void
@@ -392,6 +416,35 @@ tree_store_test_move_after_NULL (TreeStore     *fixture,
   check_model (fixture, new_order, -1);
 }
 
+static void
+tree_store_test_move_after_single (void)
+{
+  GtkTreeIter iter;
+  GtkTreeIter iter_copy;
+  GtkTreeStore *store;
+
+  store = gtk_tree_store_new (1, G_TYPE_INT);
+
+  /* Check if move-after on a store with a single node does not corrupt
+   * the store.
+   */
+
+  gtk_tree_store_append (store, &iter, NULL);
+  iter_copy = iter;
+
+  gtk_tree_store_move_after (store, &iter, NULL);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  gtk_tree_store_move_after (store, &iter, &iter);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  g_object_unref (store);
+}
+
 /* move before */
 
 static void
@@ -494,6 +547,35 @@ tree_store_test_move_before_NULL (TreeStore     *fixture,
   check_model (fixture, new_order, -1);
 }
 
+static void
+tree_store_test_move_before_single (void)
+{
+  GtkTreeIter iter;
+  GtkTreeIter iter_copy;
+  GtkTreeStore *store;
+
+  store = gtk_tree_store_new (1, G_TYPE_INT);
+
+  /* Check if move-after on a store with a single node does not corrupt
+   * the store.
+   */
+
+  gtk_tree_store_append (store, &iter, NULL);
+  iter_copy = iter;
+
+  gtk_tree_store_move_before (store, &iter, NULL);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  gtk_tree_store_move_before (store, &iter, &iter);
+  g_assert (iters_equal (&iter, &iter_copy));
+  g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+  g_assert (iters_equal (&iter, &iter_copy));
+
+  g_object_unref (store);
+}
+
 /* main */
 
 int
@@ -539,6 +621,8 @@ main (int    argc,
   g_test_add ("/tree-store/swap-end", TreeStore, NULL,
              tree_store_setup, tree_store_test_swap_end,
              tree_store_teardown);
+  g_test_add_func ("/tree-store/swap-single",
+                  tree_store_test_swap_single);
 
   /* moving */
   g_test_add ("/tree-store/move-after-from-start", TreeStore, NULL,
@@ -562,6 +646,8 @@ main (int    argc,
   g_test_add ("/tree-store/move-after-NULL", TreeStore, NULL,
              tree_store_setup, tree_store_test_move_after_NULL,
              tree_store_teardown);
+  g_test_add_func ("/tree-store/move-after-single",
+                  tree_store_test_move_after_single);
 
   g_test_add ("/tree-store/move-before-next", TreeStore, NULL,
              tree_store_setup, tree_store_test_move_before_next,
@@ -581,6 +667,8 @@ main (int    argc,
   g_test_add ("/tree-store/move-before-NULL", TreeStore, NULL,
              tree_store_setup, tree_store_test_move_before_NULL,
              tree_store_teardown);
+  g_test_add_func ("/tree-store/move-before-single",
+                  tree_store_test_move_before_single);
 
   return g_test_run ();
 }